import absunitPkg from './absunit.js'
import { GlobalVar } from '../../globalvar.js';
import fillinfo from '../fillinfo.js';

class BaseGraphUnit extends absunitPkg.AbsStruct {
    constructor() {
        super();
        this.lineMode = 1;
        this.lineJoin = 1;
        this.lineCap = 1;
        this.lineWidth = GlobalVar.defaultLineWidth;
        this.fillMode = 0;
        this.fillInfo = null;
        this.stArrowType = "none";
        this.endArrowType = "none";

        //下面参数为作为模具图元时的控制参数
        this.hornSizeCtrlFlag = 0;//0-尺寸不变 1-随模具主容器矩形 2-自由调整
        this.hornPostionCtrlFlag = 0;//尺寸不变时横向位置控制参数，0-左侧跟随容器 1--右侧跟随容器

        this.verticalSizeCtrlFlag = 0;//0-尺寸不变 1-随模具主容器矩形 2-自由调整
        this.verticalPostionCtrlFlag = 0;//尺寸不变时横向位置控制参数，0-顶部跟随容器 1--底部跟随容器
        this.disInSymbolFlag = 1;//作为模具图元时是否显示
        this.exflag = false;
    }

    translate(tx,ty){
        if (this.pos){
            this.pos.offset(tx,ty);
        }
        this.translateSubInfo(tx,ty);
        this.scope_left += tx;
        this.scope_top += ty;
        this.scope_right += tx;
        this.scope_bottom += ty;
    }

    toJson(jsonobj) { 
        super.commonPropToJson(jsonobj);
        jsonobj["lineMode"] = this.lineMode;
        jsonobj["lineJoin"] = this.lineJoin;
        jsonobj["lineCap"] = this.lineCap;
        jsonobj["lineWidth"] = this.lineWidth;
        jsonobj["fillMode"] = this.fillMode;

        if (this.fillInfo){
            jsonobj["fillInfo"] = this.fillInfo.toJson();
        }

        jsonobj["stArrowType"] = this.stArrowType;
        jsonobj["endArrowType"] = this.endArrowType;

        jsonobj["hornSizeCtrlFlag"] = this.hornSizeCtrlFlag;
        jsonobj["hornPostionCtrlFlag"] = this.hornPostionCtrlFlag;
        jsonobj["verticalSizeCtrlFlag"] = this.verticalSizeCtrlFlag;
        jsonobj["verticalPostionCtrlFlag"] = this.verticalPostionCtrlFlag;
        jsonobj["disInSymbolFlag"] = this.disInSymbolFlag;
        jsonobj["exflag"] = this.exflag;
        
        return jsonobj;
        
    }
    fromJson(jsonobj) { 
        super.commonPropFromJson(jsonobj);
        this.lineMode = jsonobj["lineMode"];
        this.lineJoin = jsonobj["lineJoin"];
        this.lineCap = jsonobj["lineCap"];
        this.lineWidth = jsonobj["lineWidth"];
        this.color = jsonobj["color"];

        this.fillMode = jsonobj["fillMode"];

        let tmp = jsonobj["fillInfo"];
        if (tmp){
            this.fillInfo = new fillinfo.LGXFillDefInfo();
            this.fillInfo.fromJson(tmp);
        }

        this.stArrowType = jsonobj["stArrowType"];
        this.endArrowType = jsonobj["endArrowType"];

        this.hornSizeCtrlFlag = jsonobj["hornSizeCtrlFlag"];
        this.hornPostionCtrlFlag = jsonobj["hornPostionCtrlFlag"];
        this.verticalSizeCtrlFlag = jsonobj["verticalSizeCtrlFlag"];
        this.verticalPostionCtrlFlag = jsonobj["verticalPostionCtrlFlag"];
        this.disInSymbolFlag = jsonobj["disInSymbolFlag"];
        
        this.exflag = jsonobj["exflag"];
    }

    cloneCopy(pNewInfo) {
        super.cloneBaseProp(pNewInfo);
        pNewInfo.lineMode = this.lineMode;
        pNewInfo.lineJoin = this.lineJoin;
        pNewInfo.lineCap = this.lineCap;
        pNewInfo.lineWidth = this.lineWidth;
        pNewInfo.fillMode = this.fillMode;
        pNewInfo.stArrowType = this.stArrowType;
        pNewInfo.endArrowType = this.endArrowType;

        pNewInfo.hornSizeCtrlFlag = this.hornSizeCtrlFlag;
        pNewInfo.hornPostionCtrlFlag = this.hornPostionCtrlFlag;
        pNewInfo.verticalSizeCtrlFlag = this.verticalSizeCtrlFlag;
        pNewInfo.verticalPostionCtrlFlag = this.verticalPostionCtrlFlag;
        pNewInfo.disInSymbolFlag = this.disInSymbolFlag;
        pNewInfo.exflag = this.exflag;
        
        //拷贝对象值，不能拷贝对象指针
        if (this.fillInfo){
            pNewInfo.fillInfo = new fillinfo.LGXFillDefInfo();
            pNewInfo.fillInfo.clone(this.fillInfo);
        }
        return pNewInfo;
    }
}

export default { BaseGraphUnit }